<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ page import="com.beaut.project.util.StaticData" %>
<%@ include file="/public/header.jsp"%>
<%
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
%>
<html>
	<head>
		<title>班组垫款待办事项</title>
			<link href="<%=contextPath%>/public/css/smart_wizard_vertical.css" rel="stylesheet"	type="text/css">
		<script type="text/javascript" src="<%=contextPath%>/public/js/jquery.smartWizard.js"></script>
		<link  rel="stylesheet"  href  ="<%=contextPath%>/public/swfupload/css/swfupload.css">
	
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
		  <script  type="text/javascript"  src="<%=contextPath%>/core/js/datastructs.js"  ></script>
			<script  type="text/javascript"  src="<%=contextPath%>/core/js/sys.js"  ></script>
			<script  type="text/javascript"  src="<%=contextPath%>/core/js/prototype.js"  ></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/attachMenu.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/Menu.js"></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/fileprogress.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/handlers.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.queue.js"  ></script>
	<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery("#searchValue").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch();
	       	} 
		});
		jQuery("#searchValue1").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch1();
	       	} 
	   	}); 
		jQuery("#dept_id").combotree({
			url:'<%=contextPath %>/springMVC/group/listDepartment',
			method:'POST',
			animate:true,
			lines:true,
			onChange:function(){
				doSearch();
			}
		});
		
		var typeArr=new Array("内部班组","外部分包商");
		jQuery('#gd_worker_id').combogrid({
			idField:"id",
			textField:"worker_company",
			title:'分包商资料',
			panelWidth:550,
			panelHeight:400,
			rownumbers:true,
			url:'<%=contextPath%>/springMVC/crm/listPageWorker',
			loadMsg:'正在加载数据，请稍后......',
			fitColumns:true,
			frozenColumns:[[
			    {title:'主键',field:'id',hidden:true}
			]],
			columns:[[
				{title:'分包商类别',field:'type_id',width:200,align:'center',formatter:function(value,rowData,rowIndex){
					return typeArr[rowData.type_id];
				}},
				{title:'公司名称',field:'worker_company',width:200,align:'center'},
				{title:'负责人',field:'worker_person',width:200,align:'center'},
				{title:'联系方式',field:'contact',width:200,align:'center'}
			]],
			pageSize:10,
			pageList : [10,50,100],  
			pagination:true,
			toolbar:'#tb1',
			onChange:function(){
				doSearch();
			}
		});
		jQuery("#dd").hide();
		
		jQuery("#table").datagrid({
			title:"班组垫款待办事项",
			iconCls:'icon-zc',
			loadMsg:'正在加载数据，请稍后......',
			url:'<%=contextPath %>/springMVC/gd/listFinanceGdAdvances?zc_status=1',
			rownumbers:true,
			fitColumns:true,
			singleSelect:true,
			nowrap:false,
			idField:'id',
			frozenColumns:[[
			      {field:'ck',checkbox:true},
			      {title:'主键',field:'id',hidden:true}
			]],
			columns:[[
				{title:'所属部门',field:'dept_name',width:100,align:'center'},
				{title:'工单编号',field:'gd_code',width:100,align:'center'},
				{title:'班组',field:'fb_advances',width:100,align:'center'},
				{title:'日期',field:'operation_date',width:100,align:'center',sort:true},
				{title:'金额',field:'money',width:100,align:'center'},
				{title:'利率',field:'rate',width:100,align:'center'},
				{title:'当前状态',field:'status_desc',width:60,align:'center'},
				{title:'经办人',field:'person_name',width:100,align:'center'},
				{title:'摘要',field:'remark',width:200,align:'center'},
				{title:'查看凭证',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
                	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:showLoanOrAdvances('"+rowData.id+"');\"/>&nbsp;&nbsp;";

				}}
			]],
			pageSize:10,
			pageList : [10,50,100],  
			pagination:true,
			onLoadSuccess:function(rtJson){
				//预留状态判断，以后工单完工之后不允许修改。
				//if(""){
					//$("#add").hide();
					//$("#jdwc").hide();
				//}
				if(rtJson.rtState== '1')
				{
					$.messager.alert('提示',rtJson.rtMsrg);
				}
			}
		});
		
		
	});
	function showLoanOrAdvances(id){
		var url= "<%=contextPath%>/springViews/gd/addOrEditAdvances.jsp?isShow=1&id="+id;
		openDialogResize(url,1000,800);
	}
	
	  function doSearch()
		{
			var searchValue = jQuery('#searchValue').val();
			jQuery('#table').datagrid('load',{
				searchValue:searchValue
			});
		}
		
		function updateGdActualFinance(){
			var rows=jQuery('#table').datagrid('getSelections');
			var deleteVar="";
			var moneys=0;
			var arrGdCode="";
			if(rows.length==0)
			{
				jQuery.messager.alert('提示','选中要放款的垫款单');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
					arrGdCode+=rows[i].gd_code;
				}else
				{
					deleteVar+=rows[i].id+",";
					arrGdCode+=rows[i].gd_code+",";
				}
					moneys+= parseFloat(rows[i].money);
			}
			jQuery.messager.confirm('确认','您确认放款这些垫款单吗？',function(msg){
				if(msg){
					jQuery('#dd').dialog({
				        title: '请选择公司账户对应的银行卡',
				        width: 200,
				        height: 67,
				        top:110,
				        closed: false,
				        cache: false,
				        href: '',
				        modal: true
				        });
					jQuery("#dd").show();
					
					jQuery('#bank_id').combogrid({
						idField:"id",
						textField:"account",
						title:'公司账户',
						panelWidth:550,
						panelHeight:200,
						rownumbers:true,
						url:'<%=contextPath %>/springMVC/finance/listPageFinanceCompany?flag=1',
						rownumbers:true,
						fitColumns:true,
						singleSelect:true,
						idField:'id',
						frozenColumns:[[
						    {title:'主键',field:'id',hidden:true}
						]],
						columns:[[
							{title:'银行',field:'bank',width:200,align:'center'},
							{title:'卡号',field:'account',width:200,align:'center'},
							{title:'开户人',field:'owner',width:100,align:'center'},
							{title:'金额',field:'money',width:100,align:'center'}
						]],
						pageSize:10,
						pageList : [10,50,100],  
						pagination:true,
						toolbar:'#tb1',
						onChange:function(){
							var row = jQuery('#bank_id').combogrid("grid").datagrid('getSelected');
							jQuery('#bank').val(row.bank);
							jQuery('#finance_company_id').val(row.id);
							jQuery('#account').val(row.account);
							jQuery('#money').val(row.money);
							showDilog(deleteVar,moneys,rows,arrGdCode);
						}
					});
				}
			});
		}
		function showDilog(deleteVar,moneys,rows,arrGdCode){
			var money=jQuery('#money').val();
			var bank=jQuery('#bank').val();
			var finance_company_id=jQuery('#finance_company_id').val();
			var account=jQuery('#account').val();
			if(parseFloat(money)>parseFloat(moneys)){
			if(money==0){
				jQuery.messager.alert('提示','请先选择使用的公司账户(银行卡)');  
				return false;
			}else{
				jQuery('#dd').dialog('close'); 
				jQuery.messager.confirm('确认','此公司账户(银行卡)</br>'+bank+'</br>卡号：'+account+'支出金额('+moneys+')',function(msg){
					if(msg){
						jQuery.ajax({
								type:'POST',
								url:"<%=contextPath %>/springMVC/gd/updateGdActualAdvances",
								data:"ids="+deleteVar+"&money="+moneys+"&finance_company_id="+finance_company_id+"&arrGdCode="+arrGdCode,
								dataType:"json",
								success:function(rtJson){
									if(rtJson.rtState == '0'){
										warningInfo(rtJson.rtMsrg);
										table_reload(rows.length);
										
									}
									else{
									jQuery.messager.alert('提示：',rtJson.rtMsrg);
									}
								}
							});
							}
					}
				)}
			}else{
				jQuery.messager.alert('提示','此公司账户(银行卡)</br>'+bank+'</br>卡号：'+account+'</br>金额('+money+')不足以支付。请选择其他账户（银行卡）');  
				jQuery('#dd').dialog('close'); 
			}
		}
		function doSearch() {
			var start_time=jQuery('#start_time').datebox('getValue');  
			var end_time=jQuery('#end_time').datebox('getValue'); 
			var searchValue=jQuery('#searchValue').val();
			var dept_id = jQuery("#dept_id").combotree('getValue');
			var gd_worker_id = jQuery("#gd_worker_id").combotree('getValue');
			jQuery('#table').datagrid('load', {
				start_time:start_time,
				end_time:end_time,
				searchValue:searchValue,
				dept_id:dept_id,
				gd_worker_id:gd_worker_id
			});
		}
		function doSearch1() {
			var searchValue = jQuery('#searchValue1').val();
			var type_id = jQuery('#type_id').val();
			jQuery('#gd_worker_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				type_id : type_id
			});
		}
	</script>
	</head>
	<body>
		
					
							<div id="table"  data-options="toolbar:'#tb',fit:true"></div>  
								<div id="tb" style="padding:3px;height:auto">
								<div style="float:left;">
								<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="updateGdActualFinance();">垫款</a>
							</div>
						<div align="right">
								开始时间：<input id="start_time" name="start_time" class="easyui-datebox" style="width:100px" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:100px"/>
								所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree" style="width:140px">&nbsp;&nbsp; 
								班组：<input type="text" id="gd_worker_id" name="gd_worker_id"   style="width:100px">
								工单编号/名称：<input id="searchValue" name="searchValue" style="width:120px" title="工单编号/名称"  placeholder="工单编号/名称 "/>&nbsp;&nbsp; 
								<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
						</div>
					</div>
			<div id="tb1" style="padding:3px;height:auto">
			<div align="right">
				分类：<select id="type_id" class="" name="type_id"  onchange="doSearch1()">   
					     <option value="" selected></option> 
					    <option value="0">内部班组</option>   
					    <option value="1">外部分包商</option>   
					</select>  
				查询条件：<input id="searchValue1" name="searchValue1" style="width:150px" title="分包商名称或负责人"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch1();"></a>
			</div>
		</div>
			<div id="dd"  style="margin-top:-200px;">
				<div style="text-align:center;">
					<input type="text" id="bank_id" name="bank_id"  data-options="required:true">
				</div>
			</div>
				<input type="hidden" id="bank" name="bank" />
				<input type="hidden" id="finance_company_id" name="finance_company_id" />
				<input type="hidden" id="account" name="account" />	
				<input type="hidden" id="money" name="money" value="0" />	
	</body>
</html>